<template>
  <div class="widget_settings_pro">
    <ele-form-section
        labelPosition="left"
        v-model="formData"
        :request-fn="handleSubmit"
        :sections="sections"
    >
      <template v-slot:form-btn="{ btns }">
        <div class="rest-btn" @click="reset">
          <svg-icon icon-class="reset-settings"></svg-icon>
          重置配置
        </div>
      </template>
    </ele-form-section>
  </div>
</template>

<script>
import { debounce } from '@/utils/utils';
export default {
    name: 'mailSubscriptionsForm',
    props: {
        value: {
            type: Object,
            default: () => ({})
        }
    },
    computed: {
        formData: {
            get () {
                return JSON.parse(this.value.styleJson);
            },
            set: debounce(function (newValue) {
                this.pageCount++;
                if (this.pageCount !== 1) {
                    this.value.styleJson = JSON.stringify(newValue);
                    this.$store.commit('SET_PROJECT_DATA', this.value);
                }
            }, 600)
        }
    },
    data () {
        return {
            pageCount: 0,
            activeNames: [],
            uploadPath: process.env.VUE_APP_BASE_API + '/upload-file',
            sections: [
                {
                    title: '编辑文案',
                    formDesc: {
                        'title': {
                            type: 'input',
                            label: '标题'
                        },
                        'sub_title': {
                            type: 'ele-form-quill-edit',
                            label: '副标题'
                        },
                        'btn_title': {
                            type: 'ele-form-quill-edit',
                            label: '按钮订阅'
                        },
                        'title_thank': {
                            type: 'ele-form-quill-edit',
                            label: '感谢订阅标题'
                        },
                        'sub_title_thanks': {
                            type: '感谢订阅副标题',
                            label: '副标题'
                        }
                    }
                }
            ]
        };
    },
    methods: {
        handleResponse (response, file, fileList) {
            return response;
        },
        handleSubmit (data) {
            console.log(data);
            return Promise.resolve();
        },
        handleRemove (index, record) {
            this.formData.blocks.splice(index, 1);
        },
        reset () {
            this.pageCount = 0;
            this.$emit('resetData', this.value);
        }
    }
};
</script>

<style scoped lang="scss">
.form-item-inline{
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 10px;
  padding-right: 10px;
  color: #606266;
  height: 32px;
  margin-bottom: 10px;
}
.editForm{
  margin-bottom: 10px;
  .form-item{
    margin-top: 10px;
    label {
      display: block;
      height: 32px;
      line-height: 32px;
    }
  }
  ::v-deep .el-collapse-item__content{
    border: 1px solid #d8deec;
    border-top:0;
    padding-left: 10px;
  }
}
.addBtn{
  width: 100%;
}
</style>
